//pages/end/end.js
//获取应用实例
var app = getApp();
var rights = [];
Page({
  //页面初始数据
  data: {
    list: {},
    right: 0,
    wrong: 0
  },
  
  //生命周期函数--监听页面加载
  onLoad: function (options) {
    //console.log(app.globalData);
    for(var i = 0; i < app.globalData.wrongPaper.right.length; i++) {
      if(app.globalData.wrongPaper.right[i] == 1) {
        this.setData({
          right: this.data.right + 1,
        })
        //console.log(this.data.right)
      }
      else {
        this.setData({
          wrong: this.data.wrong + 1,
        })
        //console.log(this.data.wrong)
      }
    }
    var list = app.globalData.wrongPaper;
    this.setData({
      list: list,
    })
    rights = this.data.list.right;
  },

  //存储错题
  storage() {
    var wrongtitle = [];
    var that = this;
    wx.getStorage({
      key: 'wrongtitle',
      success: function(res) {
        wrongtitle = res.data;
        //console.log(wrongtitle);
        for(var i = 0; i < rights.length; i++) {
          if(rights[i] == 0) {
            wrongtitle.push(that.data.list.equation[i] + that.data.list.result[i])
          }
        }
        console.log(wrongtitle);
        wx.setStorage({
          key: 'wrongtitle',
          data: wrongtitle,
        })
      },
      fail: function(res) {
        //console.log(res)
        for(var i = 0; i < rights.length; i++) {
          if (rights[i] == 0) {
            wrongtitle.push(that.data.list.equation[i] + that.data.list.result[i])
          }
        }
        //console.log(wrongtitle)
        wx.setStorage({
          key: 'wrongtitle',
          data: wrongtitle,
        })
      }
    })
  },

  //返回首页
  toindex() {
    this.storage();
    wx.reLaunch({
      url: '../practice/practice',
    })
  },

  //生命周期函数--监听页面初次渲染完成
  onReady: function() {

  },

  //生命周期函数--监听页面显示
  onShow: function() {

  },

  //生命周期函数--监听页面隐藏
  onHide: function() {

  },

  //生命周期函数--监听页面卸载
  onUnload: function() {
    
  },

  //页面相关事件处理函数--监听用户下拉动作
  onPullDownRefresh: function() {

  },

  //页面相关事件处理函数--页面上拉触底事件的处理函数
  onReachBottom: function() {

  },

  //用户点击右上角分享
  onShareAppMessage: function() {

  }
})
